package com.atguigu.day07.test;

/**
 * @version 1.0
 * @Author 马冰
 * @Date 2024/11/6 16:33
 * @注释 输入两点坐标，求取两点之间的距离
 */
public class Point {
    int x;
    int y;
    //传输两个坐标，计算两个坐标的距离
    public double getDistance(Point p1, Point p2) {
        return Math.sqrt((p1.x - p2.x) * (p1.x -p2.x) + (p1.y - p2.y) * (p1.y -p2.y));
    }
    //借用隐藏条件this，达成传输一个坐标，计算两点之间的距离
    public double getDistance(Point p) {
        return Math.sqrt((this.x - p.x) * (this.x -p.x) + (this.y - p.y) * (this.y -p.y));
    }

}
class PointTest{
    public static void main(String[] args) {
        Point p1 = new Point();
        p1.x = 5;
        p1.y = 5;
        Point p2 = new Point();
        p2.x = 10;
        p2.y = 10;
        //使用p1进行调用方法，方法中的this就默认为p1
        System.out.println(p1.getDistance(p2));
        System.out.println(p1.getDistance(p1, p2));

    }
}
